<template>
  <div class="app">
    <div class="bigbox" v-if="loading">
      <NuxtImg class="bigloading" src="/img/logo.gif" alt="" />
    </div>

    <NuxtLayout name="layout">
      <NuxtLoadingIndicator color="#0a8c6a" :height="4" :throttle="0" />
      <NuxtPage />
    </NuxtLayout>
    <LazyLoginhome />
    <LazyRechange/>
    <LazyWithdrawal/>
    <div class="kefu" :class="isKefu && !active ? 'iskefu' : ''" :style="{ left: kefux, top: kefuy }">
      <div class="closerank">
        <strong></strong>
        <h3>{{ $t("language.kefu.name") }}</h3>
        <span>
          <el-icon color="#b5b6c8" size="16" @click="isKefu = false">
            <Close />
          </el-icon>
        </span>
      </div>
      <main>
        <dl>
          <dd @click="jump('https://t.me/magicaplay_bot')">
            <img src="/img/kefu1.png" alt="" />
            <el-button color="#0a906c">{{
      $t("language.kefu.icon1")
    }}</el-button>
          </dd>
          <dd @click="jump('https://t.me/magicaplay_bot')">
            <img src="/img/c27.jpg" alt="" />
            <el-button color="#0a906c">{{ $t("language.kefu.icon2") }}</el-button>
          </dd>
          <dd @click="jump('https://m.facebook.com/')">
            <img src="/img/c28.png" alt="" /><el-button color="#0a906c">{{ $t("language.kefu.icon3")
              }}</el-button>
          </dd>
          <dd>
            <img src="/img/c29.png" alt="" /><el-button color="#0a906c">{{ $t("language.kefu.icon4")
              }}</el-button>
          </dd>
        </dl>
      </main>
    </div>
    <div id="draggable">
      <NuxtImg id="draggableimg" @click.stop.prevent="isKefu = !isKefu" src="/img/kefuimg.png"></NuxtImg>
    </div>
  </div>


</template>
<script setup lang="ts">
import { Close } from '@element-plus/icons-vue'
import { ref, onMounted, computed } from "vue"

let store = useStore()
// 首屏loading
let loading = computed(() => store.firstLoading)
//跳转url
let jump = (url: string) => {
  window.open(url);
};
//客服弹窗
let isKefu = ref(false)
let active = false;
let currentX = ref(0)
let currentY = ref(0)
let kefux = ref<string | number>('2000px')
let kefuy = ref<string | number>('400px')
onMounted(() => {
  // 关闭首屏loading
  store.$patch({
    firstLoading: false
  })
  // 设置初始化语言
  if (Object.keys(store.lang).length == 0) {
    store.$patch({
      lang: {
        img: "/img/guoqi_01.png",
        name: "English",
        lang: "en",
      }
    })

  }
  if (store.avatar == "") {
    store.$patch({
      avatar: "/img/avatar1.png"
    })
  }
  // 首屏加载

  let dragItem: any = document.getElementById('draggable');
  let dragItemimg: any = document.getElementById('draggableimg');
  dragItemimg.addEventListener('mousedown', function (e: any) {
    e.preventDefault();
  });
  dragItem.addEventListener('mousedown', function (e: any) {
    e.preventDefault();
    active = true;
    currentX.value = e.clientX - dragItem.offsetLeft;
    currentY.value = e.clientY - dragItem.offsetTop;
  });
  document.addEventListener('mouseup', function (e) {
    active = false;
    // isKefu.value = true
    if ((e.clientX - currentX.value) > 400) {
      kefux.value = (e.clientX - currentX.value - 400) + 'px'
    } else {
      kefux.value = (e.clientX - currentX.value + 107) + 'px'
    }
    if ((e.clientY - currentY.value) > 490) {
      kefuy.value = (e.clientY - currentY.value - 410) + 'px'
    } else {
      kefuy.value = (e.clientY - currentY.value + 17) + 'px'
    }
  });
  document.addEventListener('mousemove', function (e) {
    if (active) {
      e.preventDefault();
      dragItem.style.left = (e.clientX - currentX.value) + 'px';
      dragItem.style.top = (e.clientY - currentY.value) + 'px';

    }
  });
})

</script>
<style scoped lang="scss">
.app {
  width: 100%;
  height: 100%;

  .bigbox {
    background-color: rgb(15, 16, 18);
    position: fixed;
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    left: 0;
    top: 0;
    z-index: 2000;
    // @include flex(row, center, center);

    .bigloading {
      width: 300px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);

    }
  }

  #draggable {
    position: fixed;
    bottom: 40px;
    right: 40px;
    cursor: pointer;
    width: 87px;
    z-index: 20;
img {
  width: 100%;
}

  }

  .kefu {

    height: 0;
    position: fixed;
    width: 0;
    z-index: 18;
    overflow: hidden;
    background-color: #31353e;
    border-radius: 10px;
    opacity: 0;
    transition: opacity 0.3s ease;

    .closerank {
      width: 100%;
      @include flex(row, space-between, center);
      border-bottom: 1px solid #4a4c53;
      padding: 20px 20px 10px;

      strong {
        width: 30px;
        display: block;
      }

      h3 {
        font-size: 18px;
        color: #b5b6c8;
        text-align: center;
        flex: 1;
      }

      span {
        display: block;
        width: 28px;
        height: 28px;
        @include flex(row, center, center);
        border: 2px solid #b5b6c8;
        border-radius: 16px;
        cursor: pointer;
      }
    }


    main {
      padding: 65px 0 0;
      width: 100%;
      overflow-y: scroll;


      &::-webkit-scrollbar {
        width: 0;
        height: 0;
        display: none;
      }

      dl {
        padding: 0 20px;

        dd {
          height: 65px;
          padding: 10px 15px;
          @include flex(row, space-between, center);
          border-radius: 10px;
          margin-bottom: 20px;
          background: #454952;

          img {
            width: 45px;
            border-radius: 22.5px;
          }

          .el-button {
            font-size: 12px;
            color: #fff;
            width: 130px;
            height: 32px;
            line-height: 32px;
            text-align: center;
            background: #0a906c;
            border-radius: 5px;
            border: none;
          }
        }
      }
    }
  }

  .iskefu {
    opacity: 1;
    width: 400px;
    height: 490px;
  }

}
</style>
